package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.product.mapper.BaseCategory1Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory2Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory3Mapper;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Hao
 * @date: 2022/12/22 19:20
 */
@Service
public class BaseCategoryServiceImpl implements BaseCategoryService {
    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;

    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;

    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;

    /**
     * 直接查询一级分类列表
     * @return
     */
    @Override
    public List<BaseCategory1> getCategory1() {
        List<BaseCategory1> list = baseCategory1Mapper.selectList(null);
        return list;
    }

    /**
     * 根据一级分类的ID查询二级分类集合
     * @param category1Id  一级分类ID
     * @return
     */
    @Override
    public List<BaseCategory2> getCategory2(Long category1Id) {
        //1.构建查询条件
        LambdaQueryWrapper<BaseCategory2> queryWrapper = new LambdaQueryWrapper<BaseCategory2>();
        queryWrapper.eq(BaseCategory2::getCategory1Id,category1Id);
        //2.执行查询
        List<BaseCategory2> list = baseCategory2Mapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 根据二级分类的ID查询三级分类集合
     * @param category2Id  二级分类ID
     * @return
     */
    @Override
    public List<BaseCategory3> getCategory3(Long category2Id) {
        LambdaQueryWrapper<BaseCategory3> queryWrapper = new LambdaQueryWrapper<BaseCategory3>();
        queryWrapper.eq(BaseCategory3::getCategory2Id,category2Id);
        List<BaseCategory3> list = baseCategory3Mapper.selectList(queryWrapper);
        return list;
    }

}
